package com.bjpowerrnode.streamTest1;

import com.bjpowerrnode.streamTest1.pojo.App;
import com.bjpowerrnode.streamTest1.pojo.User;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

public class FilterTest {
    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        users.add(new User("sxt1",20,1));
        users.add(new User("sxt2",21,2));
        users.add(new User("sxt3",22,3));
        users.add(new User("sxt4",23,4));
        users.add(new User("sxt5",24,1));
        users.add(new User("sxt6",25,1));

        List<Integer> integers = new ArrayList<>();
        integers.add(10);
        integers.add(20);
        integers.add(13);
        integers.add(19);

        App app1 = new App();
        app1.setUser(users);
        app1.setPerson(integers);


        App app2 = app1;
        App app3 = new App();
        app3 = app1;

        app1.getUser().get(0).setId(100);

        System.out.println( app1.getUser().get(0));
        System.out.println( app2.getUser().get(0));
        System.out.println( app3.getUser().get(0));

        List<App> apps = new ArrayList<>();
        apps.add(app1);
        apps = apps.stream().filter(app -> app.getPerson().contains(20)).collect(Collectors.toList());
        System.out.println(apps);
        for (App app : apps) {
            List<User> user = app.getUser();
            app.setUser(user.stream().filter(user1 -> {if(user1.getId() == 2){
                return true;
            }
                return user1.getId().equals(1);
            }).collect(Collectors.toList()));
        }
        System.out.println(apps);
    }
}
